package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test5 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {

        Class cls = Class.forName("reflect.Person");
        Object o = cls.newInstance();
        Method[] methods = cls.getMethods();
        for (Method method : methods) {
            if (
             method.getModifiers()==Modifier.PUBLIC
                     &&
             method.getParameterCount()==0
                    &&
             method.getName().contains("s")

            ){
            System.out.println("调用方法:"+method.getName()+"()");
            method.invoke(o);

            }
        }

}
}